package exchange

import (
	"banzhuan/models"
	"encoding/json"
	"log"
)

func CreateOrder(ticks int,side string,symbol string,step_count int) string {
	createNewOrder:=new(models.CreateNewOrder)
	createNewOrder.Ticks=ticks
	createNewOrder.Side=side
	createNewOrder.Market=symbol
	createNewOrder.Lots=step_count
	createNewOrder.Type=0

	postData,_:=json.Marshal(createNewOrder)
	body:=EncyMd5(string(postData),"order","new")
	log.Println(string(body))
	OrderRespon:=new(models.OrderRespon)

	err:=json.Unmarshal(body,&OrderRespon)
	if err!=nil {
		return err.Error()
	}

	if OrderRespon.State!="ACCEPTED" {
		return "OrderRespon error"
	}

	return "true"

}
